package com.szz.demo.component;

import com.szz.demo.enums.EnumType;
import com.szz.demo.strategy.NumberStrategy;
import com.szz.demo.strategy.concrete.NumberAStrategyConcrete;
import com.szz.demo.strategy.concrete.NumberBStrategyConcrete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 孙中正
 * @date 2024/5/11 13:52
 */

@Component
public class NumberComponent {

    private final Map<EnumType, NumberStrategy> numberStrategyMap = new HashMap<>();

    @Autowired
    public NumberComponent(List<NumberStrategy> list) {
        for (NumberStrategy numberStrategy : list) {
            if (numberStrategy instanceof NumberAStrategyConcrete) {
                numberStrategyMap.put(EnumType.A, numberStrategy);
            } else if (numberStrategy instanceof NumberBStrategyConcrete){
                numberStrategyMap.put(EnumType.B, numberStrategy);

            }
        }
    }


    public String select(EnumType enumType,String a) {
        return numberStrategyMap.get(enumType).select(a);
    }



}
